package javapop.framework.parser;

import javapop.framework.ParseContext;
import javapop.framework.ParseInput;
import javapop.framework.ParseNull;
import javapop.framework.ParseResult;
import javapop.framework.Parser;

public class Forget extends Parser<Object> {
	private Parser<?> child;
	
	public Forget(Parser<?> child) {
		if(child==null) {
			throw new IllegalArgumentException("Child parser is <null>");
		}
		this.child = child;
	}
	
	@Override
	public String getDescription() {
		return child.getDescription();
	}
	
	@Override
	public boolean isMemoized() {
		return false;
	}
	
	@Override
	public ParseResult<?> eval(ParseContext<?> ctx, ParseInput input) {
		ParseResult<?> result = child.parse(ctx,input);
		if(result.isError()) {
			return (ParseResult<?>) result.asError();
		}
		
		return new ParseNull();
	}

}
